<template>
	<view>
		<view class="erwei-box m-flex-y u-flex-between">
			<view class="u-flex-1 er-box">
				<image class="er-img" :src="eRwei.qrocde"></image>
			</view>
			<view class="f-box">
				<view class="f-card u-flex u-flex-around u-flex-items-center">
					<view class="m-flex-y u-flex-items-center u-rela"
						@click="isMini() ? '' : shareClick('WXSceneSession')">
						<u--image mode="widthFix" width="30" :src="oss + '/mine/p-w.png'"></u--image>
						<view class="u-m-t-5">微信</view>
						<!-- #ifndef APP-PLUS -->
						<button open-type="share" class="share-btn"></button>
						<!-- #endif -->
					</view>
					<view class="m-flex-y u-flex-items-center" @click="wechatClick">
						<u--image mode="widthFix" width="30" :src="oss + '/mine/p-q.png'"></u--image>
						<view class="u-m-t-5">朋友圈</view>
					</view>
					<!-- #ifndef MP-WEIXIN -->
					<view class="m-flex-y u-flex-items-center" @click="shareClick('sinaweibo')">
						<u--image mode="widthFix" width="30" :src="oss + '/mine/p-b.png'"></u--image>
						<view class="u-m-t-5">微博</view>
					</view>
					<!-- #endif -->
					<!-- downloadFile('image', eRwei.qrocde) -->
					<view class="m-flex-y u-flex-items-center" @click="downloadFile('image', eRwei.qrocde)">
						<u--image mode="widthFix" width="30" :src="oss + '/mine/p-x.png'"></u--image>
						<view class="u-m-t-5">保存</view>
					</view>
				</view>
			</view>
		</view>
		<zhuanfa ref="zhuanfa"></zhuanfa>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				eRwei: {}
			};
		},
		async onLoad() {
			let res = await this.require('getErweima');
			if (res) {
				//生成二维码
				this.eRwei = res;
			}
		},
		//分享 "menu"
		async onShareAppMessage(res) {
			if (res.from === 'button') {
				return {
					title: '',
					path: '/pages/tabbar/index?share=share&agentid=' + uni.getStorageSync('userId'),
					imageUrl: this.eRwei.qrocde
				};
			} else {
				this.$refs.zhuanfa.handShareFa();
				return {
					title: '',
					path: '/pages/tabbar/index?share=share&agentid=' + uni.getStorageSync('userId'),
					imageUrl: this.eRwei.qrocde
				};
			}
		},
		methods: {
			shareClick(scene) {
				// #ifdef APP-PLUS
				uni.share({
					provider: 'weixin',
					scene,
					type: 0,
					title: this.company,
					imageUrl: this.eRwei.qrocde,
					href: '/pages/tabbar/index?share=share&agentid=' + uni.getStorageSync('userId'),
					success: function(res) {},
					fail: function(err) {}
				});
				// #endif
			},
			wechatClick() {
				// #ifdef MP-WEIXIN
				this.$refs.zhuanfa.handleShowFa();
				// #endif
				// #ifdef APP-PLUS
				this.shareClick('WXSceneTimeline');
				// #endif
			},
			preservation() {
				// #ifdef MP-WEIXIN
				let _this = this
				uni.downloadFile({
					url: _this.eRwei.qrocde, //这里为图片路径  
					success: (res1) => {
						if (res1.statusCode == 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res1.tempFilePath,
								success: function(res2) {
									uni.showToast({
										title: '保存成功'
									})
								},
								fail: function() {
									uni.showToast({
										title: '保存失败，请稍后重试！',
										icon: 'none'
									})
								}
							});
						}
					}
				});
				// #endif
			}
		}
	};
</script>

<style lang="scss" scoped>
	.erwei-box {
		height: 100vh;
		overflow: hidden;
		background-image: url('https://neidangjia.oss-accelerate.aliyuncs.com/mine/z-bg.png');
		background-size: 100vw 100vh;
		background-position: left top;
		background-repeat: no-repeat;
	}

	.er-box {
		background-image: url('https://neidangjia.oss-accelerate.aliyuncs.com/mine/r-tyx.png');
		background-size: 690rpx 100%;
		background-position: 30rpx 100%;
		background-repeat: no-repeat;
	}

	.er-img {
		position: relative;
		width: 300rpx;
		height: 300rpx;
		top: 56%;
		left: 50%;
		transform: translate(-50%, 0);
	}

	.f-box {
		flex-shrink: 0;
		padding: 30rpx;
	}

	.f-card {
		padding: 10rpx;
		height: 120rpx;
		background-color: #fff;
		border-radius: 15rpx;
	}
</style>
